
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <include file="./Public/Admin/header.html" />
</head>
<body>
<div id="main">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="box">
                    <div class="box-title">
                        <div class="span4">
                            <h3><i class="icon-table"></i>用户角色管理</h3>
                        </div>
                    </div>
                    <div class="box-content">
                        <div class="row-fluid">
                            <div class="span12 control-group">
                                <div class="span4">
                                    <a class="btn" href="{:U('Admin/Permission/addtypes')}?action=add"><i class="icon-plus"></i>添加用户角色</a>
                                    <a class="btn" href="javascript:location.reload()"><i class="icon-refresh"></i>刷新</a>
                                </div>
                                <div class="pull-left datatabletool" >
                                    <button class="btn" title="批量删除" attr='BatchDel'><i class="icon-remove"></i>批量删除</button>
                                </div>
                            </div>
                        </div>

                        <div class="row-fluid dataTables_wrapper">
                            <table id="listTable" class="table table-bordered table-hover  dataTable">
                                <thead>
                                <tr>
                                    <th class='with-checkbox'>
                                        <input type="checkbox" class="check_all" /></th>
                                    <th>角色名称</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <?php foreach($types as $item):?>
                                <tr>
                                    <td class="with-checkbox">
                                        <input type="checkbox" name="check" value="<?php echo $item['user_type_id'];?>">
                                    </td>
                                    <td style="text-align:left;">
                                        <?php echo $item['user_type_name'];?>
                                    </td>
                                    <td class='hidden-480'>
                                        <if condition="$item.user_type_id neq 1">
                                        <a href="{:U('Admin/Permission/addtypes')}?action=edit&user_type_id=<?php echo $item['user_type_id'];?>" class="btn" rel="tooltip" title="编辑"><i class="icon-edit"></i>编辑</a>
                                        </if>
                                        <if condition="$item.user_type_id gt 2">
                                        <a href="javascript:void(0);" class="btn" rel="tooltip" title="删除" attr="deltext_<?php echo $item['user_type_id'];?>"><i class="icon-remove"></i>删除</a>
                                        </if>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                                <?php if($total==0):?>
                                <tr><td align="center" colspan="10">暂无记录</td></tr>
                                <?php endif;?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        var delText = function(event){
            console.log(event.data.tid);
            G.ui.tips.confirm_flag('您确定要删除吗?',function(){
                $.post("{:U('Admin/Permission/delusertype')}", {tid:event.data.tid},function(data){
                    if (data.errno ==0)
                    {
                        location.reload();
                    } else {
                        G.ui.tips.err(data.error);
                    }
                },'json');
            });
        };

        $("a[attr^='deltext_']").each(function(){
            var tmp = $(this).attr('attr').split('_');
            var id=new Array();
            id[0]=tmp[1];
            $(this).bind("click", {tid:id}, delText);
        });

        $("[attr='BatchDel']").click(function(){
            var check = $("input:checked").not($(".check_all")[0]);
            if(check.length<1){
                alert('请选择删除项');
                return false;
            }
            G.ui.tips.confirm_flag('您确定要删除吗?',function(){
                var id = new Array();
                check.each(function(i){
                    id[i] = $(this).val();
                });
                $.post("{:U('Admin/Permission/delusertype')}", {tid:id},function(data){
                    if (data.errno ==0)
                    {
                        location.reload();
                    } else {
                        G.ui.tips.err(data.error);
                        //alert(data.error);
                    }
                },'json');
            });
        });

        $("#btn_search").click(function(){
            var keywords = $.trim($('#keyword').val());
            if (keywords.length <= 0) {
                //alert('请输入搜索关键字.');
                //$('#keyword').focus();
                //return false;
            }
            //window.location.href = '/wechat/replytext/aid/'+$('#aid').val()+'/type/'+$('#select_type').val()+'/keywords/' + keywords;
        });

        $("#keyword").keyup(function(e) {
            if (e.keyCode == 13) {
                $("#btn_search").click();
                return false;
            }
        });




    });
</script>
<?php echo isset($msg)?$msg:'';?>
</body>
</html>
